package com.efounder.activity;

import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.viewpager.widget.ViewPager;

import com.efounder.adapter.OrderPagerAdapter;
import com.efounder.chat.activity.BaseActivity;
import com.efounder.chat.widget.BadgeView;
import com.efounder.mobilemall.R;

import java.util.List;


/**
 * Created by will on 18-2-2.
 * 商城订单界面
 */

public class MallOrderActivity extends BaseActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private String[] titles;
    private List<BadgeView> mBadgeViews;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_my_order);

        titles = getResources().getStringArray(R.array.order_types);
        tabLayout = (TabLayout) findViewById(R.id.tablayout);
        viewPager = (ViewPager) findViewById(R.id.viewpager);

        initViewPager();
        initTabLayout();
    }

    private void initViewPager() {
        viewPager.setAdapter(new OrderPagerAdapter(getSupportFragmentManager(), titles));
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initTabLayout() {
        for (int i=0;i<titles.length;i++) {
            tabLayout.addTab(tabLayout.newTab().setText(titles[i]));
        }
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.getTabAt(0).select();
//        ImageView imageView = new ImageView(this);
//        View view = tabLayout.getTabAt(0).getCustomView();
//        TabLayout.Tab tab = tabLayout.getTabAt(0);
//        TextView textView = new TextView(this);
//        textView.setGravity(Gravity.CENTER);
//        textView.setText("全部");
//        tab.setCustomView(textView);
//        BadgeView badgeView = new BadgeView(this, textView);
//        badgeView.setGravity(Gravity.RIGHT|Gravity.TOP);
//        badgeView.setText("1");
//        badgeView.show();
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
}
